import { Component } from '@angular/core';
import {NavController, NavParams } from 'ionic-angular';
import {HttpServies} from '../../providers/http-servies';
import {LoginPage} from "../login/login";
import 'rxjs/add/operator/toPromise';
import {UserPage} from "../user/user";
@Component({
  selector: 'page-contact',
  templateUrl: 'contact.html',
  providers:[HttpServies]
})
export class ContactPage {
  userInfo = {
    'mobile': '',
    'password': ''
  }
  constructor(public navCtrl: NavController, private http:HttpServies,public navParams: NavParams) {


  }
  ligPage(){
    this.navCtrl.push(LoginPage);
  }
  checkInfo() {
    if (!this.userInfo.mobile|| !this.userInfo.password ) {
      this.http.showErro("请输入完整信息");
      return;
    }
    var param = "mobile=" + this.userInfo.mobile+"&password=" + this.userInfo.password;
    this.http.httpPost('/home/mine/login', param)
        .then(res => {
          if (res && res.code ==1) {
            this.http.showErro(res.msg);
            console.log(res.msg);
            localStorage.setItem("mobile",this.userInfo.mobile);
            localStorage.setItem("token",res.data);
            this.navCtrl.push(UserPage);
          }else {
            this.http.showErro(res.msg);
          }
        })
  }
}
